package com.bruan.threadpool;

import java.util.concurrent.*;

public class ThreadPoolTest {
    public static void main(String[] args) {
        //创建线程池对象
//        ThreadPoolExecutor(int corePoolSize,int maximumPoolSize,long keepAliveTime,TimeUnit unit,
//        BlockingQueue<Runnable> workQueue,
//        ThreadFactory threadFactory,
//        RejectedExecutionHandler handler)
        ThreadPoolExecutor pool = new ThreadPoolExecutor(3,5,8,TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(4),Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        Runnable target = new MyRunnable();
        //创建一个线程池，自动处理任务
        pool.execute(target);//忙
        pool.execute(target);//忙
        pool.execute(target);//忙
        pool.execute(target);//任务队列
        pool.execute(target);//任务队列
        pool.execute(target);//任务队列
        pool.execute(target);//任务队列
        pool.execute(target);//创建临时线程
        pool.execute(target);//创建临时线程
        pool.execute(target);//拒绝任务


    }
}
